import fetch from '@/utils/fetch'

export function MP (ak) {
  return new Promise(function (resolve, reject) {
    window.init = function () {
      resolve(BMap)
    }
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://api.map.baidu.com/api?v=2.0&ak=" + ak + "&callback=init";
    script.onerror = reject;
    document.head.appendChild(script);
  })
}

export function getLocationNearby (query, ak) {
  return fetch({
    url: 'http://api.map.baidu.com/place/v2/search?region=上海&output=json',
    method: 'get',
    params: query,
    ak
  })
}
